function [chi2_values,donors_value,chi2_values_2,acceptors_value] = chi_calculate(donors,acceptors)
%计算供体位点卡方
bases = {'a', 'c', 'g', 't'};  % 碱基类型
chi2_values = zeros(18, 18);  % 初始化 χ² 值矩阵
Y = zeros(18,18);
for i = 1:17   %第一个位点
    for j = i+1:18   %第二个位点
         contingency_table = zeros(4,4);   %初始化4×4联列表
        for k = 1:length(donors)
           temper = donors{k};
           base_i = find(strcmp(bases,temper(i)));
           base_j = find(strcmp(bases,temper(j)));
           contingency_table(base_i, base_j) = contingency_table(base_i, base_j) + 1;   %第i位为x且第j位为y
        end   %
%-----------------------------------------------------------------------------%
%计算卡方
        Y(i,j) = sum(sum(contingency_table));
        s = 0;
        for m = 1:4
            for n = 1:4
                e_mn = sum(contingency_table(m,:))*sum(contingency_table(:,n))/Y(i,j);
                s = s + ((contingency_table(m,n)-e_mn)^2)/e_mn;
            end
        end
        chi2_values(j,i) = s;
        chi2_values(i,j) = s;
%-----------------------------------------------------------------------------%
    end   %j
end   %i
chi2_values(isnan(chi2_values)) = 0;
donors_value = zeros(18,18);   %将卡方值大于55.4491的标记为1
for i = 1:18
    for j = 1:18
        if(chi2_values(i,j)>55.4491)
            donors_value(i,j) = 1;
        end
    end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%计算受体位点卡方
bases = {'a', 'c', 'g', 't'};  % 碱基类型
chi2_values_2 = zeros(36, 36);  % 初始化 χ² 值矩阵
Y_2 = zeros(36,36);
for i = 1:35   %第一个位点
    for j = i+1:36   %第二个位点
            contingency_table = zeros(4,4);   %初始化4×4联列表
        for k = 1:length(acceptors)   %k和l遍历donors中的每段序列
            temper = char(acceptors{k});
            base_i = find(strcmp(bases,temper(i)));
            base_j = find(strcmp(bases,temper(j)));
            contingency_table(base_i, base_j) = contingency_table(base_i, base_j) + 1;   %第i位为x且第j位为y 
        end   %k
%-----------------------------------------------------------------------------%
%计算卡方
        Y_2(i,j) = sum(sum(contingency_table));
        s = 0;
        for m = 1:4
            for n = 1:4
                e_mn = sum(contingency_table(m,:))*sum(contingency_table(:,n))/Y_2(i,j);
                s = s + ((contingency_table(m,n)-e_mn)^2)/e_mn;
            end
        end
        chi2_values_2(j,i) = s;
        chi2_values_2(i,j) = s;
%-----------------------------------------------------------------------------%
    end   %j
end   %i
chi2_values_2(isnan(chi2_values_2)) = 0;
acceptors_value = zeros(36,36);   %将卡方值小于27.8772的标记为0
for i = 1:36
    for j = 1:36
        if(chi2_values_2(i,j)>27.8772)
            acceptors_value(i,j) = 1;
        end
    end
end
end